<template>
    <div>
        <el-dialog :title="'添加店铺'+$route.name" :visible="goodsListVisible" @update:visible="v=>$emit('update:goodsListVisible',false)">
            <el-form>
                <el-form-item label="商品名称:" label-width="120px">
                    <el-input v-model="goodsForm.goodsName" autocomplete="off" style="width:200px"></el-input>
                </el-form-item>
                <el-form-item label="是否推荐:" label-width="120px">
                    <input type="radio" v-model="goodsForm.isTrue" :value="'是'">是
                    <input type="radio" v-model="goodsForm.isTrue" :value="'否'">否
                </el-form-item>

                <el-form-item label="商品图片:" label-width="120px">
                    <el-upload
                            :headers="{
                              authorization:$store.state.admin.token
                            }"
                            name="goodsPic"
                            :data="goodsForm"
                            ref="upload"
                            :limit="1"
                            :auto-upload="false"
                            :on-success="success"
                            class="upload-demo"
                            action="/api/goodsList"
                            list-type="picture">
                        <el-button size="small" type="primary">点击上传</el-button>
                        <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
                    </el-upload>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="$emit('update:goodsListVisible',false)">取 消</el-button>
                <el-button type="primary" @click="$refs.upload.submit()">提 交</el-button>
            </div>

        </el-dialog>

    </div>
</template>

<script>
    export default {
        name: "GoodsList",
        props:{
            goodsListVisible:{
                props: Boolean,
                default:false
            },
            shopTypeId:{
                type: String,
                default: ""
            }
        },
        data(){
            return{
                goodsForm:{
                    goodsName:"",
                    goodsType:"",
                    isTrue:true,
                },

            }
        },
        methods:{
            success(res){
                if(res.ok===1){
                    this.$emit('update:goodsListVisible',false)
                    this.$refs.upload.clearFiles()
                    this.goodsForm.goodsName=""
                    this.$store.dispatch("getGoodsList")
                    this.$message.success(res.msg)
                }else{
                    this.$message.error(res.msg)
                }

            }
        }
    }
</script>

<style scoped>

</style>